package LeetCode刷题;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2022-03-26 11:06
 * @description: Functions of this class is
 * 删除链表中的节点I
 **/
public class 删除链表中的重复元素IansII {
    /**
     * 删除链表中的节点I
     * 官方题解（直接删除节点即可）：
     * class Solution {
     *     public ListNode deleteDuplicates(ListNode head) {
     *         if (head == null) {
     *             return head;
     *         }
     *
     *         ListNode cur = head;
     *         while (cur.next != null) {
     *             if (cur.val == cur.next.val) {
     *                 cur.next = cur.next.next;
     *             } else {
     *                 cur = cur.next;
     *             }
     *         }
     *
     *         return head;
     *     }
     * }
     ----------------------------------------------------------
     * 我的解法（快慢指针）：
     * public ListNode deleteDuplicates(ListNode head) {
     *         if(head != null){
     *             ListNode ans = new ListNode(head.val);
     *             ListNode tail = ans;
     *             //同样使用快慢指针来操作
     *             ListNode slow = head;
     *             ListNode fast = head;
     *             while(fast != null){
     *                 if(slow.val != fast.val){
     *                     //出现了不重复的元素
     *                     //插入到新链表中
     *                     ListNode p = new ListNode(fast.val);
     *                     tail.next = p;
     *                     tail = p;
     *                     slow = fast;//然后把慢指针指向快指针的位置
     *                 }
     *                 fast = fast.next;
     *             }
     *             return ans;
     *         }
     *         return head;
     *     }
     *
     */
}